package com.dkm.ec.product.repository.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.api.model.Page;
import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ec.product.domain.ProductLike;
import com.dkm.ec.product.repository.ProductLikeRepository;
import com.dkm.ec.product.persistence.dao.ProductLikeQueryDao;
import com.dkm.ec.product.persistence.entity.ProductLikePo;

/**
 * 对象功能:商品点赞 Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2017-07-31 20:40:10
 */
@Repository
public class ProductLikeRepositoryImpl extends AbstractRepository<String, ProductLikePo,ProductLike> implements ProductLikeRepository{
	  
	@Resource
	private  ProductLikeQueryDao productLikeQueryDao;

	public ProductLike newInstance() {
		ProductLikePo po = new ProductLikePo();
		ProductLike productLike = SpringHelper.getBean(ProductLike.class);
		productLike.setData(po);
		return productLike;
	}

	public ProductLike newInstance(ProductLikePo po) {
		ProductLike productLike = SpringHelper.getBean(ProductLike.class);
		productLike.setData(po);
		return productLike;
	} 
	
	@Override
	protected IQueryDao<String, ProductLikePo> getQueryDao() {
		return productLikeQueryDao;
	}

	@Override
	public List<ProductLikePo> findByUserId(String userId,String proId) {
		Map<String, Object> params = new HashMap<>();
	 	params.put("whereSql", "prod_id_='"+proId+"' and user_type_='member'  and member_id_='"+userId+"'");
	    return productLikeQueryDao.findAll(params);
	}

	@Override
	public List<ProductLikePo> findByUserLike(String userId,Page page) {
		Map<String, Object> params = new HashMap<>();
	 	params.put("userId", userId);
	    return productLikeQueryDao.findByKey("findByUserLike", params,page);
	}
	
}
